﻿function FilterFunc() {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    setTimeout("RealFilterFunc('', 0, 30, 10, 0, 'RealFilterFunc')", 10);
}

function RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    keywords = document.getElementById("_legalDrugPermitType").options[document.getElementById("_legalDrugPermitType").selectedIndex].value; 
    retValue = Portal.SODC.IDIS.DrugTypeInfo.GetHtmlResult(keywords, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("resultcontent").innerHTML = retValue;
}

function ClientSideAddnewDrugTypeInfo() {
    DrugType = document.getElementById("_DrugPermitType").options[document.getElementById("_DrugPermitType").selectedIndex].value;
    if (DrugType == "-1") {
        alert("Chưa chọn danh mục thuốc!");
        document.getElementById("_DrugPermitType").select();
    }
    KeyName = document.getElementById("KeyName").value;
    if (KeyName == "") {
        alert("Chưa nhập tên quốc tế!");
        document.getElementById("KeyName").focus();
        return;
    }
   // KeyName = document.getElementById("KeyName").value;

    KeyDesc = document.getElementById("KeyDesc").value;    

    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    retValue = Portal.SODC.IDIS.DrugTypeInfo.ServerSideAddnewDrugTypeInfo(DrugType, KeyName, KeyDesc).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue.replace("ERROR:", ""));
        return;
    }
    //document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
    ClientResetAllFields();
    FilterFunc();
}

function ClientSideUpdateDrugTypeInfo(keyid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    DrugType = document.getElementById("_DrugPermitType").options[document.getElementById("_DrugPermitType").selectedIndex].value;
    if (DrugType == "-1") {
        alert("Chưa chọn danh mục thuốc!");
        document.getElementById("_DrugPermitType").select();
        return;
    }
    KeyName = document.getElementById("KeyName").value;
    if (KeyName == "") {
        alert("Chưa nhập tên quốc tế!");
        document.getElementById("KeyName").focus();
        return;
    }
    //KeyName = document.getElementById("KeyName").value;

    KeyDesc = document.getElementById("KeyDesc").value;
    if (KeyDesc == "") {
        alert("Chưa nhập tên khoa học!");
        document.getElementById("KeyDesc").focus();
        return;
    }

    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    retValue = Portal.SODC.IDIS.DrugTypeInfo.ServerSideUpdateDrugTypeInfo(keyid, DrugType, KeyName, KeyDesc).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
    ClientHideDiv();
    RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript);
}

function ClientHideDiv() {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    $("#divshowhide").html("");
    document.getElementById("divProcessing").innerHTML = "";
}

function ShowClientDivAddnew() {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    $("#divshowhide").html(Portal.SODC.IDIS.DrugTypeInfo.GetHtmlToAddnew().value);
    document.getElementById("divProcessing").innerHTML = "";
}

function ClientResetAllFields() {
    document.getElementById("_DrugPermitType").selectedIndex = 0;
    //document.getElementById("KeyCode").value="";
    document.getElementById("KeyName").value="";
    document.getElementById("KeyDesc").value="";
    document.getElementById("_DrugPermitType").focus();
}

function ShowClientUpdateUrlForm(recordid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";

    $("#divshowhide").html(Portal.SODC.IDIS.DrugTypeInfo.GetShowUpdateForm(recordid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript).value);
    $("#DateFoundation").datepicker({ dateFormat: 'dd/mm/yy' });

    document.getElementById("divProcessing").innerHTML = "";
}

function ClientExportData() {
    DrugType = document.getElementById("_legalDrugPermitType").options[document.getElementById("_legalDrugPermitType").selectedIndex].value;
    Ret = Portal.SODC.IDIS.DrugTypeInfo.ServerExportData(DrugType).value;
    if (Ret.indexOf("ERROR") != -1) {
        alert(Ret.replace("ERROR:", ""));
        return;
    } else {
        window.open(Ret, "_blank");
        //alert(Ret);
    }
}
